package com.network.TCP;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) {
        try {
            // 创建Socket对象，指定服务器的IP地址和端口号
            Socket socket = new Socket("localhost", 6000);

            // 获取输入流和输出流
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            // 发送消息给服务器
            out.println("Hello from client");

            // 读取服务器的响应
            String serverResponse = in.readLine();
            System.out.println("接收到服务器消息: " + serverResponse);

            // 关闭连接
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
